<?php
	require_once(ROOTDIR.'source/service/MysqlHandler.class.php');
	
	class Main
	{
		private static $mysql;
		
		public static function getMysqlInstance()
		{
			if(empty(self::$mysql))
			{
				global $dsn_user;
				self::$mysql = new MysqlHandler($dsn_user);
			}      
			else
			{
			}
		    return self::$mysql;
		}
		
		public static function setMySQLParam($parm)
		{
			unset($list);
			foreach ($parm as $k => $value)
			{
				if(strpos($k,'.'))
				{
					$temp = explode('.', $k);
					
					$key = $temp[0].".`".self::getMysqlInstance()->strescape($temp[1])."`";//`{$key}`
				}
				else
				{
					$key = "`".$k."`";//`{$key}`
				}
				
				
				if(is_array($value))
				{
					$like = $value[0];
					
					if($like == 'like')
					{
						$list[] =" {$key} {$like} '%".self::getMysqlInstance()->strescape($value[1])."%'";
					}
					elseif($like == 'in' || $like == 'not in')
					{
						$list[] =" {$key} {$like} (".$value[1].")";
					}
					elseif($like == 'is')
					{
						$list[] =" {$key} {$like} ".$value[1];
					}
					else
					{
						$list[] =" {$key} {$like} '".self::getMysqlInstance()->strescape($value[1])."'";
					}
					
				}
				else
				{
					$list[] = " {$key} ='".self::getMysqlInstance()->strescape($value)."'";
				}
				
				
			}
			return $list;
		}
		
		
	}